//
//  HomeWCApi.m
//  SSWifi
//
//  Created by 酷安 @啥也不会啊啊啊啊啊啊  on 2024/1/23.
//

#import "HomeWCApi.h"

@implementation HomeWCApi

- (NSString *)devicesName{
    return @"微闯";
}
- (WiFiDeviceTypes)deviceType{
    return WiFiDevice_WC;
}

- (void)getSupportBandCallBack:(void (^)(NSArray<BandItemModel *> * _Nullable))callback{
    BandItemModel *md1 = [[BandItemModel alloc] initWithName:@"B1" value:0];
    BandItemModel *md3 = [[BandItemModel alloc] initWithName:@"B3" value:0];
    BandItemModel *md5 = [[BandItemModel alloc] initWithName:@"B5" value:0];
    NSArray *arr = @[md1,md3,md5];
    !callback ? : callback(arr);
}

- (void)getSelectedBandCallBack:(void (^)(NSString * _Nullable))callback{
    NSDictionary *para = @{
        @"cmd": @"work_lte_band",
        @"multi_data":@"1",
    };
    [self.manage GET:[self serverHost:NO] parameters:para headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSString *str =[responseObject objectForKey:@"work_lte_band"];
        if(str.length > 0){
            NSInteger b =  [[[str componentsSeparatedByString:@","] firstObject] intValue];
            NSString *v = nil;
            if(b==21){
                v = @"B5,B3,B1,";
            }else if (b == 20){
                v = @"B5,B3";
            }else if (b == 17){
                v = @"B5,B1";
            }else if (b == 5){
                v = @"B1,B3";
            }else if (b == 16){
                v = @"B5";
            }else if (b == 4){
                v = @"B3";
            }else if (b == 1){
                v = @"B1";
            }
            !callback ? : callback(v);
        }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            !callback ? : callback(nil);
        }];
    
    
}

- (void)setBandPara:(NSString *)bands callBack:(void (^)(bool, NSString * _Nonnull))callback{
    NSArray *arr = [bands componentsSeparatedByString:@","];
    NSInteger total = 0;
    for(NSString *i in arr){
        if([i.lowercaseString isEqualToString:@"b1"]){
            total += 1;
        }else if([i.lowercaseString isEqualToString:@"b3"]){
            total += 4;
        }
        else if([i.lowercaseString isEqualToString:@"b5"]){
            total += 16;
        }
    }
    NSDictionary *para = @{
        @"goformId": @"SET_FREQ_BAND",
        @"work_lte_band":[NSString stringWithFormat:@"%@,0,0,0,0,0,0,0",@(total)],
        @"ping_google":@"0",
    };
    [self.manage GET:[self serverHost:YES] parameters:para headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if([[responseObject objectForKey:@"result"] isEqualToString:@"success"]){
            !callback ? : callback(YES,@"更改成功,设备重启中..");
            return;
        }
        !callback ? : callback(NO  ,@"更改失败");
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        !callback ? : callback(NO  ,@"更改失败");
    }];
    
    
}
@end
